﻿@{
    ViewBag.Title = "ProductCheck";
}
@section head
{
    <link href="@Url.Content("~/ScriptPlugin/easyui/themes/gray/easyui.css")" rel="stylesheet" />
    <link href="@Url.Content("~/ScriptPlugin/easyui/themes/icon.css")" rel="stylesheet" />
    <script type="text/javascript" src="@Url.Content("~/ScriptPlugin/easyui/jquery.easyui.min.js")"></script>
    <script type="text/javascript" src="@Url.Content("~/ScriptPlugin/easyui/locale/easyui-lang-zh_CN.js")"></script>
    <script type="text/javascript" src="@Url.Content("~/ScriptPlugin/easyui/plugins/datagrid-groupview.js")"></script>
    <script type="text/javascript" src="@Url.Content("~/ScriptPlugin/easyui/plugins/datagrid-detailview.js")"></script>
    <script type="text/javascript" src="@Url.Content("~/Scripts/KingsSharp.DataGrid.Filter.js")"></script>
    <script src="@Url.Content("~/Scripts/jquery.linq.min.js")"></script>
}
<div id="grid">
    <div id="toolpannel">
        <div class="content-pannel-buttons">
            <a onclick="$('#grid').datagrid('load')">
                <b class="p-icon-serch">查询</b>
            </a>
        </div>
        <div class="datagrid-filter-pannel" id="filterpannel">
            <table class="content-table-serch">
                <tr>
                    <th>
                        产品名称
                    </th>
                    <td>
                        <input type="text" name="Name" data-filter="true" />
                        <a class="p-icon-filter p-icon-filter-style" style="display: block; width: 22px;
                            height: 22px; float: left">@Html.GetFilterItem("Name", typeof(string))</a>
                        </td>
                        <th>

                        </th>
                        <td></td>
                        <th>

                        </th>
                        <td></td>
                        <th>

                        </th>
                        <td></td>
                    </tr>
                </table>
            </div>
        </div>
    </div>
    @section foot{
        <script type="text/javascript">
            var single=@ViewBag.Multi;
            function LoadCustmerInfoData()
            {
                var columns = [[
                    { field: "ck", checkbox: true },
                    { field: "Name", title: "产品/零件名称", width: 150 },
                    { field: "SaleWeight", title: "年产量/销售量", width: 85 },
                    { field: "NeedSteelWeight", title: "需钢材量", width: 85 },
                    { field: "UseSteelType", title: "使用钢材品种", width: 85 },
                    { field: "Consumption", title: "使用钢材品种单耗", width: 95 }
                ]];
                var parameter = {
                    title: null,
                    columns: columns,
                    url: "@Url.Content("~/Customer/Product/GetProductGridData")",
                    pageNumber: 1,
                    singleSelect: !single,
                    ctrlSelect: !single,
                    onCheck: checkRow,
                    onUncheck: uncheckRow,
                    onCheckAll: checkAllRow,
                    onUncheckAll: uncheckAllRow,
                    onLoadSuccess: loadSuccess
                };
                var grid = K.GetGridData("#grid", parameter).Grid;
            }
            LoadCustmerInfoData();
            var checkedRows = new Array();
            function loadSuccess() {
                var rows = $("#grid").datagrid("getRows");
                $.Enumerable.From(rows).ForEach(function (row, i) {
                    if ($.Enumerable.From(checkedRows).Where(function (x) { return x.Id == row.Id; }).Count() != 0) {
                        $("#grid").datagrid("checkRow", i);
                    }
                });
            }
            function checkRow(rows, rowData) {
                if ($.Enumerable.From(checkedRows).Where(function (x) { return x.Id == rowData.Id; }).Count() == 0) {
                    checkedRows = $.Enumerable.From(checkedRows).Union([rowData]).ToArray();
                }
            }
            function uncheckRow(rows, rowData) {
                if ($.Enumerable.From(checkedRows).Where(function (x) { return x.Id == rowData.Id; }).Count() > 0) {
                    checkedRows = $.Enumerable.From(checkedRows).Except([rowData]).ToArray();
                }
            }
            function checkAllRow(rows) {
                checkedRows = $.Enumerable.From(checkedRows).Union(rows).ToArray();
            }
            function uncheckAllRow(rows) {
                checkedRows = $.Enumerable.From(checkedRows).Except(rows).ToArray();
            }
            function SaveData(index) {
                parent.K.layer.callback(index, checkedRows);
                parent.K.layer.close(index);
            }

        </script>

    }